<template>
  <div class="container">
    <div>
      <!-- <el-button type="primary" icon="el-icon-plus" plain @click="add()">
        新增企业
      </el-button> -->
          <!-- <button @click="runPythonScript('Hello, World!')">Run Python Script</button> -->

    </div>
    <div class="search">
      <el-form
        ref="searchForm"
        :model="searchForm"
        label-width="100px"
        class="demo-ruleForm"
        :inline="true"
      >
        <div class="out_box">
          <div class="form_box_list">
            <div class="form_box">
              <div class="formItem">
                <div class="itmetitle">任务名称</div>
                <div class="iteminput">
                  <el-input
                    v-model="searchForm.enterpriseName"
                    placeholder="请输入任务名称"
                  />
                </div>
              </div>
              <!-- <div class="formItem">
                <div class="itmetitle">所属行业</div>
                <div class="iteminput">
                  <el-select
                    v-model="searchForm.enterpriseIndustry"
                    placeholder="请选择所属行业"
                    style="width: 100%"
                    :clearable="true"
                  >
                    <el-option
                      v-for="item in industry"
                      :key="item.id"
                      :label="item.name"
                      :value="item.name"
                    />
                  </el-select>
                </div>
              </div> -->
            </div>
            <!-- <div class="form_box">
              <div class="formItem">
                <div class="itmetitle">企业类型</div>
                <div class="iteminput">
                  <el-select
                    v-model="searchForm.enterpriseType"
                    placeholder="请选择企业类型"
                    style="width: 100%"
                    :clearable="true"
                  >
                    <el-option
                      v-for="item in companyType"
                      :key="item.id"
                      :label="item.name"
                      :value="item.name"
                    />
                  </el-select>
                </div>
              </div>
            </div> -->
          </div>
          <div class="item_btn">
            <el-button type="primary" @click="submitsearch('searchForm')">
              查找
            </el-button>
            <el-button type="primary" @click="resetForm('searchForm')">
              重置
            </el-button>
          </div>
          <!-- <div class="item_btn">
            <el-button type="primary" @click="resetForm('searchForm')">
              重置
            </el-button>
          </div> -->
        </div>
      </el-form>
    </div>
    <div class="myTable">
      <el-table
        :data="tableData"
        style="width: 100%; margin-top: 20px"
        ref="tableList"
      >
        <el-table-column align="center" prop="id" label="ID" width="80" />
        <el-table-column align="center" prop="grade" label="等级">
          <!-- <template slot-scope="scope">
            {{ returnName(scope.row.lssuer) }}
          </template> -->
        </el-table-column>
        <!-- <el-table-column
          align="center"
          prop="enterpriseIndustry"
          label="所属行业"
        >
          <template slot-scope="scope">
            {{ returnTypeName(scope.row.type) }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="enterpriseType"
          label="企业类型"
        />
        <el-table-column
          align="center"
          prop="enterpriseLegalper"
          label="公司法人"
        /> -->

        <el-table-column
          align="center"
          prop="createDate"
          label="创建时间"
          width="150"
        >
          <!-- <template slot-scope="scope">
            {{ returnName(scope.row.createDate) }}
          </template> -->
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="{ row, $index }">
            <el-button type="info" size="small" @click="detail(row, $index)">
              查看
            </el-button>
            <!-- <el-button
              type="primary"
              size="small"
              @click="toRelease(row, $index)"
            >
              发布
            </el-button>
            <el-button type="primary" size="small" @click="toDown(row, $index)">
              下架
            </el-button> -->
            <el-button
              type="warning"
              size="small"
              @click="toDelete(row, $index)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          layout="total, prev, pager, next, jumper"
          :page-size="10"
          :total="total"
          :current-page="searchForm.page"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogShow"
      center
      :destroy-on-close="true"
    >
      <el-form ref="Form" label-width="150px" :model="formData" :rules="rules">
        <el-form-item label="企业名称" prop="enterpriseName">
          <el-input
            v-model="formData.enterpriseName"
            placeholder="请输入企业名称"
            maxlength="32"
          />
        </el-form-item>
        <el-form-item
          label="信用代码"
          prop="enterpriseCreditCode"
          v-if="formType == 1"
        >
          <el-input
            v-model="formData.enterpriseCreditCode"
            placeholder="请输入信用代码"
            maxlength="32"
          />
        </el-form-item>
        <el-form-item
          label="法人"
          prop="enterpriseLegalper"
          v-if="formType == 1"
        >
          <el-input
            v-model="formData.enterpriseLegalper"
            placeholder="请输入法人"
            maxlength="12"
          />
        </el-form-item>
        <el-form-item
          label="联系电话"
          prop="enterpriseConnum"
          v-if="formType == 1"
        >
          <el-input
            v-model="formData.enterpriseConnum"
            placeholder="请输入联系电话"
            maxlength="11"
          />
        </el-form-item>
        <el-form-item label="所属行业" prop="enterpriseIndustry">
          <el-select
            v-model="formData.enterpriseIndustry"
            placeholder="请选择所属行业"
            style="width: 100%"
          >
            <el-option
              v-for="item in industry"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="企业类型" prop="enterpriseType">
          <el-select
            v-model="formData.enterpriseType"
            placeholder="请选择企业类型"
            style="width: 100%"
          >
            <el-option
              v-for="item in companyType"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="企业地址" prop="enterpriseAddress">
          <el-input
            v-model="formData.enterpriseAddress"
            placeholder="请输入企业地址"
            maxlength="200"
          />
        </el-form-item>

        <el-form-item label="企业Logo图A区：" v-if="formType != 3">
          <el-upload
            ref="upload"
            :action="url"
            :headers="headers"
            list-type="picture-card"
            :on-remove="handleRemoveLogoA"
            :class="{ hide: hideUploadLogoA }"
            :on-change="onChangeLogoA"
            accept=".jpg,.jpeg,.png,.bmp,.JPG,.JPEG,.PBG"
            :file-list="formData.srcListLogoA"
            :limit="3"
            :on-exceed="exceed"
            :on-success="handleAvatarSuccess"
          >
            <i
              v-if="imgListLogoA.length < 1"
              slot="default"
              class="el-icon-plus"
            ></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="企业Logo图B区：" v-if="formType != 3">
          <el-upload
            ref="upload"
            :action="url"
            :headers="headers"
            list-type="picture-card"
            :on-remove="handleRemoveLogoB"
            :class="{ hide: hideUploadLogoB }"
            :on-change="onChangeLogoB"
            accept=".jpg,.jpeg,.png,.bmp,.JPG,.JPEG,.PBG"
            :file-list="formData.srcListLogoB"
            :limit="3"
            :on-exceed="exceed"
            :on-success="handleAvatarSuccess"
          >
            <i
              v-if="imgListLogoB.length < 1"
              slot="default"
              class="el-icon-plus"
            ></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="企业简介图：" v-if="formType != 3">
          <el-upload
            ref="upload"
            :action="url"
            :headers="headers"
            list-type="picture-card"
            :on-remove="handleRemoveIntroduce"
            :class="{ hide: hideUploadIntroduceImg }"
            :on-change="onChangeIntroduce"
            accept=".jpg,.jpeg,.png,.bmp,.JPG,.JPEG,.PBG"
            :file-list="formData.srcListIntroduce"
            :limit="5"
            :on-exceed="exceed"
            :on-success="handleAvatarSuccess"
          >
            <i
              v-if="imgListIntroduce.length < 5"
              slot="default"
              class="el-icon-plus"
            ></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="企业宣传图竖屏区：" v-if="formType != 3">
          <el-upload
            ref="upload"
            :multiple="true"
            :action="url"
            :headers="headers"
            list-type="picture-card"
            :class="{ hide: hideUploadXuanChuanImgA }"
            :on-remove="handleRemoveXuanChuanImgA"
            :on-change="onChangeXuanChuanImgA"
            accept=".jpg,.jpeg,.png,.bmp,.JPG,.JPEG,.PBG"
            :file-list="formData.srcXuanChuanListA"
            :limit="limitNum"
            :on-exceed="exceed"
            :on-success="handleAvatarSuccess"
          >
            <i slot="default" class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="企业宣传图横屏区：" v-if="formType != 3">
          <el-upload
            ref="upload"
            :multiple="true"
            :action="url"
            :headers="headers"
            list-type="picture-card"
            :on-remove="handleRemoveXuanChuanImgB"
            :class="{ hide: hideUploadXuanChuanImgB }"
            :on-change="onChangeXuanChuanImgB"
            accept=".jpg,.jpeg,.png,.bmp,.JPG,.JPEG,.PBG"
            :file-list="formData.srcXuanChuanListB"
            :limit="limitNum"
            :on-exceed="exceed"
            :on-success="handleAvatarSuccessB"
          >
            <i slot="default" class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="语音上传：">
          <el-upload
            class="avatar-uploader"
            :action="urlVid"
            :headers="headers"
            :limit="limitNum"
            :on-remove="handleRemoveSound"
            list-type="picture"
            :class="{ hide: hideUploadSound }"
            :on-success="handleSoundSuccess"
            :before-upload="beforeUploadVideo"
            accept=".mp3"
            :on-change="onChangeSound"
            :on-progress="vidProgress"
          >
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="视频上传：">
          <el-upload
            class="avatar-uploader"
            :action="urlVid"
            :headers="headers"
            :limit="limitNum"
            :on-remove="handleRemoveVideo"
            list-type="picture"
            :on-success="handleVideoSuccess"
            :class="{ hide: hideUploadVideo }"
            :before-upload="beforeUploadVideo"
            accept=".mp4,.mov,.rmvb,.avi,.wmv,.mp3,.flv"
            :on-change="onChangeVideo"
            :on-progress="vidProgress"
          >
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="企业简介：" prop="enterpriseIntroduce">
          <el-input
            v-model="formData.enterpriseIntroduce"
            type="textarea"
            maxlength="500"
          />
        </el-form-item>
        <div class="btsbox" v-if="formType != 3">
          <el-button
            v-if="formType == 1"
            type="primary"
            @click="submitForm('Form')"
          >
            确定
          </el-button>

          <el-button @click="dialogShow = false">取消</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import {
  // addCompany,
  // deleteCompany,
  // deleteFile,
  findAllTask,
} from "@/api/task";
import { errMsg, succMsg } from "./../../utils/message";
import hasDirective from "/src/directive/permission/btnPermiss.js";
const { exec } = require('child_process');

export default {
  directives: {
    has: hasDirective,
  },
  data() {
    const checkPhone = (rule, value, callback) => {
      if (value.trim() == "") {
        callback();
        return;
      } else if (!/^1[34578]\d{9}$/.test(value)) {
        callback(new Error("请输入正确手机号!"));
      } else {
        callback();
      }
    };
    return {
      url: `${process.env.VUE_APP_BASE_API}/admin/resource/upload`,
      urlVid: `${process.env.VUE_APP_BASE_API}/admin/resource/upload`,
      fileList: [],
      imgListLogoA: [],
      imgListLogoB: [],
      imgListIntroduce: [],
      imgListXuanChuanA: [],
      imgListXuanChuanB: [],
      videoList: [],
      soundList: [],
      limitNum: 10,
      hideUploadLogoA: false,
      hideUploadLogoB: false,
      hideUploadIntroduceImg: false,
      hideUploadXuanChuanImgA: false,
      hideUploadXuanChuanImgB: false,
      hideUploadSound: false,
      hideUploadVideo: false,
      showPress: false,
      addExlShow: false,
      headers: {
        TOKEN: localStorage.getItem("token"),
      },
      //action: `${process.env.VUE_APP_BASE_API}/crab/importExcel`,
      exlForm: {
        file: {},
      },
      companyType: [
        {
          id: 0,
          name: "民营",
        },
        {
          id: 1,
          name: "合资",
        },
        {
          id: 2,
          name: "独资",
        },
        {
          id: 3,
          name: "国有",
        },
        {
          id: 4,
          name: "私营",
        },
        {
          id: 5,
          name: "全民所有制",
        },
        {
          id: 6,
          name: "集体所有制",
        },

        {
          id: 8,
          name: "股份制",
        },
        {
          id: 9,
          name: "有限责任",
        },
      ],
      industry: [
        {
          id: 0,
          name: "A农、林、牧、渔业",
        },
        {
          id: 1,
          name: "B采矿业",
        },
        {
          id: 3,
          name: "C制造业",
        },
        {
          id: 4,
          name: "D电力、热力、燃气及水生产和供应业",
        },
        {
          id: 5,
          name: "E建筑业",
        },
        {
          id: 6,
          name: "F批发和零售业",
        },
        {
          id: 7,
          name: "G交通运输、仓储和邮政业",
        },
        {
          id: 8,
          name: "H住宿和餐饮业",
        },
        {
          id: 9,
          name: "I信息传输、软件和信息技术服务业",
        },
        {
          id: 10,
          name: "J金融业",
        },
        {
          id: 11,
          name: "K房地产业",
        },
        {
          id: 12,
          name: "L租赁和商务服务业",
        },
        {
          id: 13,
          name: "M科学研究和技术服务业",
        },
        {
          id: 14,
          name: "N水利、环境和公共设施管理业",
        },
        {
          id: 15,
          name: "O居民服务、修理和其他服务业",
        },
        {
          id: 16,
          name: "P教育",
        },
        {
          id: 17,
          name: "Q卫生和社会工作",
        },
        {
          id: 18,
          name: "R文化、体育和娱乐业",
        },
        {
          id: 19,
          name: "S公共管理、社会保障和社会组织",
        },
        {
          id: 20,
          name: "T国际组织",
        },
      ],
      tableData: [],
      total: 0,
      selectData: [],
      searchForm: {
        // page: 1,
        // enterpriseName: "",
        // enterpriseType: "",
        // enterpriseIndustry: "",
      },
      dialogShow: false,
      dialogTitle: "",
      formType: "",
      btnText: "确认",
      formData: {
        enterpriseName: "",
        enterpriseCreditCode: "",
        enterpriseLegalper: "",
        enterpriseConnum: "",
        enterpriseIndustry: "",
        enterpriseType: "",
        enterpriseAddress: "",
        enterpriseLogoA: "",
        enterpriseLogoB: "",
        enterpriseIntroduceImg: "",
        enterpriseXuanChuanImgA: "",
        enterpriseXuanChuanImgB: "",
        enterpriseVideo: "",
        enterpriseIntroduce: "",
      },
      oldFormData: {},
      rules: {
        enterpriseName: [
          {
            required: true,
            message: "企业名称不能为空",
            trigger: "blur",
          },
        ],
        enterpriseCreditCode: [
          {
            required: true,
            message: "信用代码不能为空",
            trigger: "blur",
          },
        ],
        enterpriseLegalper: [
          {
            required: true,
            message: "法人不能为空",
            trigger: "blur",
          },
        ],
        enterpriseConnum: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
          { validator: checkPhone, trigger: "blur" }, // 自定义校验
        ],
      },
      CardType: [],
      CardLssuer: [],
      StatusList: [
        {
          code: 0,
          name: "未核销",
        },
        {
          code: 1,
          name: "已核销",
        },
      ],
    };
  },
  created() {
    // this.createAndDownloadTxtFile();
    // this.create2()

    // 使用函数生成文件
    // this.createFile("example.txt", "这是文件内容", true); // 文件已存在，会被覆盖
    // this.testt();
    // createFile("newfile.txt", "新文件内容", false); // 文件不存在，会创建新文件
    this.getCompanyList();
  },
  methods: {
    returnName(data) {
      if (data == "") {
        return;
      }
      let time =
        data.substring(0, 4) +
        "-" +
        data.substring(4, 6) +
        "-" +
        data.substring(6, 8);
      return time;
    },
    onChangeLogoA(file, fileList) {
      this.imgListLogoA = fileList;
      this.hideUploadLogoA = fileList.length >= 1;
    },
    onChangeLogoB(file, fileList) {
      this.imgListLogoB = fileList;
      this.hideUploadLogoB = fileList.length >= 1;
    },
    onChangeIntroduce(file, fileList) {
      this.imgListIntroduce = fileList;
      this.hideUploadIntroduceImg = fileList.length >= 5;
    },
    onChangeXuanChuanImgA(file, fileList) {
      this.imgListXuanChuanA = fileList;
      this.hideUploadXuanChuanImgA = fileList.length >= this.limitNum;
    },
    onChangeXuanChuanImgB(file, fileList) {
      this.imgListXuanChuanB = fileList;
      this.hideUploadXuanChuanImgB = fileList.length >= this.limitNum;
    },
    onChangeSound(file, fileList) {
      this.soundList = fileList;
      this.hideUploadSound = fileList.length >= this.limitNum;
    },
    onChangeVideo(file, fileList) {
      this.videoList = fileList;
      this.hideUploadVideo = fileList.length >= this.limitNum;
    },

    handleRemoveLogoA(file, fileList) {
      this.imgListLogoA = fileList;
      this.hideUploadLogoA = fileList.length >= 3;
    },
    handleRemoveLogoB(file, fileList) {
      this.imgListLogoB = fileList;
      this.hideUploadLogoB = fileList.length >= 3;
    },
    handleRemoveIntroduce(file, fileList) {
      this.imgListIntroduce = fileList;
      this.hideUploadIntroduceImg = fileList.length >= 5;
    },
    handleRemoveXuanChuanImgA(file, fileList) {
      this.imgListXuanChuanA = fileList;
      this.hideUploadXuanChuanImgA = fileList.length >= this.limitNum;
    },
    handleRemoveXuanChuanImgB(file, fileList) {
      this.imgListXuanChuanB = fileList;
      this.hideUploadXuanChuanImgB = fileList.length >= this.limitNum;
    },
    handleRemoveSound(file, fileList) {
      this.soundList = fileList;
      this.hideUploadSound = fileList.length >= this.limitNum;
    },
    handleRemoveVideo(file, fileList) {
      this.videoList = fileList;
      this.hideUploadVideo = fileList.length >= this.limitNum;
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
      console.log(res, this.imageUrl);
    },
    handleAvatarSuccessB(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
      console.log(res, this.imageUrl);
    },
    //上传文件
    importFn() {
      this.fileList = [];
      this.addExlShow = true;
    },
    //下载模板
    download() {
      var token = localStorage.getItem("token");
      window.location.href = `${process.env.VUE_APP_BASE_API}/crab/downloadTemplate?TOKEN=${token}`;
    },
    handleChangePic(file, fileList) {
      if (fileList.length > 1) {
        fileList.splice(0, 1);
      }
    },
    uploadFiles(e) {
      if (e.success) {
        succMsg(e.msg);
        this.addExlShow = false;
        this.fileList = [];
        // this.getList();
      } else {
        errMsg(e.msg);
      }
    },
    exlBtnsubmit() {
      this.$refs.batchExcel.submit();
    },
    exlCancel() {
      this.fileList = [];
      this.addExlShow = false;
    },
    getCompanyList() {
      findAllTask({
        ...this.searchForm,
      }).then((res) => {
        // if (res.code == 200) {
        //   console.log(res);
        //   this.tableData = res.data.rows;
        //   this.total = res.data.records;
        // }
        if (res.code == "00000") {
          this.tableData = res.data;
          this.total = res.data.length;
        }
      });
    },
    // 创建本地文件
    createAndDownloadTxtFile() {
      // 创建文件内容
      const content = "这里是文件内容";
      const blob = new Blob([content], { type: "text/plain;charset=utf-8" });
      // 创建并触发下载
      const url = URL.createObjectURL(blob);
      const link = document.createElement("a");
      link.href = url;
      link.setAttribute("download", "wtest.py");
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    },

    // create2() {
    // 创建一个函数来生成文件
    createFile(filename, content, overwrite = false) {
      // 检查文件是否已存在
      if (overwrite || !window.localStorage.getItem(filename)) {
        // 存储文件内容
        window.localStorage.setItem(filename, content);
        console.log("文件已覆盖生成：", filename);
      } else {
        console.log("文件已存在，未进行覆盖。");
      }
    },
    // },
    testt() {
      const { exec } = require("child_process");

      const input = "5"; // 传递给 Python 脚本的参数

      exec(
        `python D://code/python-learn/test4.py ${input}`,
        (error, stdout, stderr) => {
          if (error) {
            console.error(`执行Python脚本时发生错误: ${error}`);
            return;
          }

          const result = parseInt(stdout.trim()); // 获取 Python 脚本的输出并转换为整数
          console.log(`Python脚本的输出: ${result}`);
        }
      );

      // const { exec, spawn } = require("child_process");
      // const {exec} = window.require('child_process');
      // exec("D:/code/python-learn/test3.py", (err, stdout, stderr) => {
      //   if (err) {
      //     console.error(`执行Python脚本时发生错误: ${error}`);
      //     return;
      //   }
      // });

      // exec(
      //   `python D:/code/python-learn/test4.py ${input}`,
      //   (error, stdout, stderr) => {
      //     if (error) {
      //       console.error(`执行Python脚本时发生错误: ${error}`);
      //       return;
      //     }

      //     const result = parseInt(stdout.trim()); // 获取 Python 脚本的输出并转换为整数
      //     console.log(`Python脚本的输出: ${result}`);
      //   }
      // );
      // const { PythonShell } = require("python-shell");

      // // 创建要传递给Python脚本的数组
      // const myArray = [1, 2, 3, 4, 5];

      // // 配置PythonShell选项
      // const options = {
      //   args: myArray,
      // };

      // //运行Python脚本，并处理结果
      // PythonShell.run(
      //   "D:/code/python-learn/test5.py",
      //   options,
      //   function (err, result) {
      //     // if (err) throw err;
      //     if (error) {
      //       console.error(`执行Python脚本时发生错误: ${error}`);
      //       return;
      //     }

      //     // 处理Python脚本的输出结果
      //     console.log(result);
      //   }
      // );

      // let options = {
      //   mode: "text",
      //   pythonPath: "path/to/python",
      //   pythonOptions: ["-u"], // get print results in real-time
      //   scriptPath: "path/to/my/scripts",
      //   args: ["value1", "value2", "value3"],
      // };

      // PythonShell.run("my_script.py", options).then((messages) => {
      //   // results is an array consisting of messages collected during execution
      //   console.log("results: %j", messages);
      // });
      // let pyshell = new PythonShell('D:/code/python-learn/test5.py');
      // pyshell.on('message', function(message) { 
      //  })
      // // PythonShell.run("D:/code/python-learn/test5.py", null).then((messages) => {
      // //   console.log("finished");
      // // });
      // let py = PythonShell.run("D://code/python-learn/test6.py", null, function (err, results) {
      //   console.log("results: %j", results);
      // });
    },
    runPythonScript(arg) {
      // const scriptPath = 'D://code/python-learn/script.py';
      // exec(scriptPath, (error, stdout, stderr) => {
      //   if (error) {
      //     console.error(`exec error: ${error}`);
      //     return;
      //   }
      //   console.log(`stdout: ${stdout}`);
      //   if (stderr) {
      //     console.error(`stderr: ${stderr}`);
      //   }
      // });
      // let options = {
      //   mode: "text",
      //   pythonPath: "path/to/python",
      //   pythonOptions: ["-u"], // get print results in real-time
      //   scriptPath: "path/to/my/scripts",
      //   args: ["value1", "value2", "value3"],
      // };

      // PythonShell.run("my_script.py", options).then((messages) => {
      //   // results is an array consisting of messages collected during execution
      //   console.log("results: %j", messages);
      // });

      const { PythonShell } = require("python-shell");
      // 创建要传递给Python脚本的数组
      const myArray = [1, 2, 3, 4, 5];

       // 配置PythonShell选项
      const options = {
        args: myArray,
      };

      //运行Python脚本，并处理结果
      // PythonShell.run(
      //   "D:/code/python-learn/test5.py",
      //   options,
      //   function (err, result) {
      //     // if (err) throw err;
      //     if (error) {
      //       console.error(`执行Python脚本时发生错误: ${error}`);
      //       return;
      //     }

      //     // 处理Python脚本的输出结果
      //     console.log(result);
      //   }
      // );

        PythonShell.run("D:/code/python-learn/test5.py", options).then((messages) => {
        // results is an array consisting of messages collected during execution
        console.log("results: %j", messages);
      });
    },
    //新增
    add() {
      this.formData.enterpriseName = "";
      this.formData.enterpriseCreditCode = "";
      this.formData.enterpriseLegalper = "";
      this.formData.enterpriseIndustry = "";
      this.formData.enterpriseConnum = "";
      this.formData.enterpriseType = "";
      this.formData.enterpriseAddress = "";
      this.formData.enterpriseLogoA = "";
      this.formData.enterpriseLogoB = "";
      this.formData.enterpriseIntroduceImg = "";
      this.formData.enterpriseVideo = "";
      this.formData.enterpriseSound = "";
      this.formData.enterpriseIntroduce = "";
      this.dialogShow = true;
      this.dialogTitle = "新增";
      this.formType = 1;
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.imgListLogoA.length > 0) {
            this.formData.enterpriseLogoA = this.imgListLogoA[0].response.data;
          }
          if (this.imgListLogoB.length > 0) {
            this.formData.enterpriseLogoB = this.imgListLogoB[0].response.data;
          }
          if (this.imgListIntroduce.length > 0) {
            this.imgListIntroduce.map((item) => {
              this.formData.enterpriseIntroduceImg += item.response.data + ",";
            });
            this.formData.enterpriseIntroduceImg =
              this.formData.enterpriseIntroduceImg.slice(
                0,
                this.formData.enterpriseIntroduceImg.length - 1
              );
          }
          if (this.imgListXuanChuanA.length > 0) {
            this.imgListXuanChuanA.map((item) => {
              this.formData.enterpriseXuanChuanImgA += item.response.data + ",";
            });
            this.formData.enterpriseXuanChuanImgA =
              this.formData.enterpriseXuanChuanImgA.slice(
                0,
                this.formData.enterpriseXuanChuanImgA.length - 1
              );
          }
          if (this.imgListXuanChuanB.length > 0) {
            this.imgListXuanChuanB.map((item) => {
              this.formData.enterpriseXuanChuanImgB += item.response.data + ",";
            });
            this.formData.enterpriseXuanChuanImgB =
              this.formData.enterpriseXuanChuanImgB.slice(
                0,
                this.formData.enterpriseXuanChuanImgB.length - 1
              );
          }
          if (this.soundList.length > 0) {
            this.soundList.map((item) => {
              this.formData.enterpriseSound += item.response.data + ",";
            });
            this.formData.enterpriseSound = this.formData.enterpriseSound.slice(
              0,
              this.formData.enterpriseSound.length - 1
            );
          }
          if (this.videoList.length > 0) {
            this.videoList.map((item) => {
              this.formData.enterpriseVideo += item.response.data + ",";
            });
            this.formData.enterpriseVideo = this.formData.enterpriseVideo.slice(
              0,
              this.formData.enterpriseVideo.length - 1
            );
          }
          addCompany({
            enterpriseName: this.formData.enterpriseName,
            enterpriseCreditCode: this.formData.enterpriseCreditCode,
            enterpriseLegalper: this.formData.enterpriseLegalper,
            enterpriseIndustry: this.formData.enterpriseIndustry,
            enterpriseConnum: this.formData.enterpriseConnum,
            enterpriseType: this.formData.enterpriseType,
            enterpriseAddress: this.formData.enterpriseAddress,
            enterpriseLogo: this.formData.enterpriseLogoA,
            enterpriseLogoB: this.formData.enterpriseLogoB,
            introductionImage: this.formData.enterpriseIntroduceImg,
            enterpriseImage: this.formData.enterpriseXuanChuanImgA,
            enterpriseImageB: this.formData.enterpriseXuanChuanImgB,
            enterpriseVideo: this.formData.enterpriseVideo,
            enterpriseSound: this.formData.enterpriseSound,
            enterpriseIntroduce: this.formData.enterpriseIntroduce,
          }).then((res) => {
            if (res.success) {
              succMsg(res.msg);
              this.getCompanyList();
              this.dialogShow = false;
            } else {
              errMsg(res.msg);
            }
          });
        }
      });
    },

    detail(row, index) {
      console.log(row, index);
      let data = row;
      this.$router.push({
        path: "companyDetail",
        query: { rowAll: JSON.stringify(data), type: 2 },
      });
    },
    toRelease(row, index) {
      // const userInfo = JSON.parse(getStorage("userInfo"));
      this.$confirm("请确认是否发布，发布后企业信息在元宇宙展示", {
        type: "warning",
      }).then(() => {
        let par = {
          id: row.id,
          // delUser: userInfo.id,
        };
        deleteFor(par).then((res) => {
          this.getForum();
        });
      });
    },
    toDown(row, index) {
      this.$confirm("请确认是否下架，下架后企业信息则不在元宇宙展示", {
        type: "warning",
      }).then(() => {
        let par = {
          id: row.id,
          // delUser: userInfo.id,
        };
        deleteFor(par).then((res) => {
          this.getForum();
        });
      });
    },
    toDelete(row, index) {
      // const userInfo = JSON.parse(getStorage("userInfo"));
      console.log(row);
      this.$confirm("确认要删除当前选中信息?", {
        type: "warning",
      }).then(() => {
        let ids = [row.enterpriseId];

        deleteCompany(ids).then((res) => {
          if (res.code == 200) this.getCompanyList();
        });
      });
    },
    exceed(files, fileList) {
      errMsg("超出数量限制！");
    },
    handleVideoSuccess(response, file, fileList) {
      file.url = require("../../assets/imgs/video.png");
      console.log(file);
    },
    handleSoundSuccess(response, file, fileList) {
      file.url = require("../../assets/imgs/sound.png");
      console.log(file);
    },
    beforeUploadVideo() {},
    deleteVideo(item) {
      console.log(this, item);
    },
    vidProgress(event, file, fileList) {
      this.showPress = true;
      this.videoUploadPercent = parseInt(event.percent);
      if (this.videoUploadPercent >= 100) {
        this.videoUploadPercent = 100;
        setTimeout(() => {
          this.showPress = false;
        }, 800);
      }
    },
    handleCurrentChange(val) {
      this.searchForm.page = val;
      this.getCompanyList();
    },
    submitsearch(formName) {
      this.getCompanyList();
    },
    resetForm(formName) {
      this.searchForm.pageNum = 1;
      this.searchForm.enterpriseIndustry = "";
      this.searchForm.enterpriseType = "";
      this.searchForm.enterpriseName = "";
      this.getCompanyList();
    },
  },
};
</script>
<style scoped>
.container {
  height: 100%;
  padding: 20px;
}

.btsbox {
  margin-top: 40px;
  display: flex;
  justify-content: space-evenly;
}

.checkitem {
  margin-top: 20px;
}

.el-checkbox-group {
  padding-left: 30%;
}

.el-checkbox__inner {
  margin-right: 19px;
}

.search {
  margin-top: 20px;
  padding: 30px 20px 30px 10px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: relative;
}

.myTable {
  margin-top: 30px;
  padding: 1px 20px 30px 20px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.out_box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form_box_list {
  width: 80%;
}

.btn_sty {
  width: 60%;
  align-self: center;
  margin: 0 auto;
  padding: 10px 0;
  border-radius: 5px;
  cursor: pointer;
  color: #606266;
  border: 1px solid #dcdfe6;
}

.btn_sty:hover {
  background-color: #e8f4ff;
}

.btn_sty:first-child {
  background-color: #1890ff;
  margin-bottom: 3%;
  border-color: #1890ff;
  color: #fff;
}

.btn_sty:first-child:hover {
  background-color: #46a6ff;
}

.form_box {
  display: flex;
  justify-content: space-between;
}

.inner_form_box {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
}

.formItem {
  width: 48%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.itmetitle {
  width: 20%;
  font-size: 14px;
  color: #606266;
  font-weight: 700;
  text-align: center;
}

.iteminput {
  width: 80%;
  display: flex;
  justify-content: space-between;
}

.form_box:nth-child(n + 2) {
  margin-top: 20px;
}

.pagination {
  margin-top: 20px;
  text-align: center;
}

.btnbox {
  display: flex;
  justify-content: space-evenly;
  margin-top: 20px;
}

.upload-demo {
  text-align: center;
}


.titles1 {
  width: 120px;
  text-align: right;
  font-size: 14px;
  font-weight: bold;
  color: #000000;
}
.btn {
  background: #fff;
  width: 100%;
  height: 60px;
  position: fixed;
  bottom: 0px;
  z-index: 999;
  margin-left: -20px;
  box-shadow: 0px 0px 5px 0px rgba(217, 216, 216, 0.5);
}
.maxinput {
  width: 80%;
}

.pops {
  width: 148px;
  height: 148px;
  position: relative;
  /* padding: 8px; */
  border: 1px dashed #d9d9d9;
  /* border: 1px solid red; */
}

/deep/.hide .el-upload--picture-card {
  display: none;
}

/deep/.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  background-color: #fbfdff;
  position: relative;
}

.video-avatar {
  width: 130px;
  height: 130px;
  margin: 8px;
}

/* 视频上传 */
P {
  position: relative;
  width: 148px;
  height: 148px;
  font-size: 14px;
  display: inline-block;
  padding: 10px;
  margin-right: 25px;
  border: 1px dashed #c0ccda;
  text-align: center;
  vertical-align: middle;
  background: #fbfdff;
  &:hover {
    cursor: pointer;
  }
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 148px;
  height: 64px;
  line-height: 64px;
  text-align: center;
}
</style>
